home *** CD-ROM | disk | FTP | other *** search
- unit PICKS; { John Haluska, CIS 74000,1106 Turbo Pascal 4.0, 5.0 }
-
- { Pick item from a vertical/horizontal bar menu by using the cursor keys to
- high lite the menu item or entering the first non blank character of the
- menu item. Text and background colors may optionally be specified.
-
- To implement a pick menu:
-
- 1. Define the row, column location and title of each menu item (10
- max).
-
- Pick[1].Row:=3; Pick[1].Column:=2; Pick[1].Title:=' A Choice ';
- " " " "
- Pick[5].Row:=3; Pick[5].Column:=30; Pick[5].Title:=' E Choice ';
-
- 2. Optional. Specify the background and text colors.
-
- BkgdColor := Blue; TextColor := LightGray;
-
- 3. Specify number of menu items, initial pick, display the menu, and
- get the Result by calling:
-
- Result := DisplayMenuGetPick(1,5); }
-
- {$R-,S-,I+,D+,F-,V-,B-,N-,L+}
-
- interface
-
- uses
- Crt;
- const
- MaxPicks = 10; { Max number of picks in menu }
- type
- pickmenu = record
- Row : integer; { location of pick }
- Column : integer; { in display menu }
- Title : string[60]; { pick item name }
- end;
-
- var
- Pick : array[1..MaxPicks] of pickmenu; { List of picks in menu }
- TxtColor,BkgdColor : byte; { Define display colors }
-
- procedure CursorOn(State : boolean);
- function DisplayMenuGetPick(InitPick,ActualPicks : integer) : integer;
-
- implementation
-
- {----------------------------------------------------------------------------}
- { CursorOn turns off (False) or turns on (True) the screen display cursor.
- Example: CursorOn(False) turns off (hides) the cursor. }
-
- procedure CursorOn(State : boolean);
-
- begin
- inline(
- $B4/$03/ { MOV AH,3 ;Call BIOS Service 3 -}
- $B7/$00/ { MOV BH,0 ; Get Cursor Position}
- $CD/$10/ { INT $10 ; & Size}
- $8A/$96/>State/ { MOV DL,>State[BP] ;Save cursor on/off in DL}
- $0A/$D2/ { OR DL,DL ;Turn cursor off?}
- $74/$06/ { JZ X1 ;Yes}
- $81/$E1/$FF/$DF/ { AND CX,$DFFF ;No, turn off bit 5 of CH}
- $EB/$04/ { JMP SHORT X2 }
- $81/$C9/$00/$20/ {X1: OR CX,$2000 ;Yes, turn on bit 5 of CH}
- $B4/$01/ {X2: MOV AH,1 ;Call BIOS Service 1 -}
- $CD/$10); { INT $10 ; Set Cursor Size}
- end; {CursorOn}
- {-----------------------------------------------------------------------------}
- procedure HiLite(On : boolean; Pick : pickmenu); { HiLite menu item }
- { Pick if On = True }
- begin
- GoToXY(Pick.Column,Pick.Row);
- if LastMode <> Mono then { Color CRT }
- if On then
- begin
- TextAttr := BkgdColor + TxtColor*16; { Reverse video }
- Write(Pick.Title);
- TextAttr := BkgdColor*16 + TxtColor;
- end
- else
- begin
- TextAttr := BkgdColor*16 + TxtColor;
- Write(Pick.Title);
- end
- else { Monochrome CRT }
- if On then
- begin
- TextAttr := LightGray*16 + Black; { Reverse video }
- Write(Pick.Title);
- TextAttr := Black*16 + LightGray;
- end
- else
- begin
- TextAttr := Black*16 + LightGray;
- Write(Pick.Title);
- end;
- end; {HiLite}
- {----------------------------------------------------------------------------}
- { Display a menu of ActualPicks items, generate string of pick first nonblank
- characters with InitPick highlighted, and return selected Pick number.
- Requires HiLite and CursorOn routines. }
-
- function DisplayMenuGetPick(InitPick,ActualPicks : integer) : integer;
-
-
- var
- I : integer;
- TempStr : string[80];
- State : boolean;
- Ch1,Ch2 : char;
- Current,Last,FirstCharSel : integer;
- FirstCharStr : string[MaxPicks];
-
- begin
- FirstCharStr := '';
- CursorOn(False); { Hide cursor }
- if LastMode <> Mono then
- begin
- TextAttr := TxtColor + BkgdColor*16;
- end;
- for I := 1 to ActualPicks do
- with Pick[I] do
- begin
- GoToXY(Column,Row);
- Write(Title);
- TempStr := Title;
- while (Length(TempStr) > 0) and (TempStr[1] = ' ') do { Remove }
- Delete(TempStr,1,1); { leading spaces }
- FirstCharStr := FirstCharStr + Copy(TempStr,1,1); { 1st non blank }
- end; { character in each title }
- HiLite(True,Pick[InitPick]); { Define initial choice }
- Current := InitPick; Last := InitPick; FirstCharSel := 0;
- repeat
- Ch1 := ReadKey;
- case Ch1 of
- #32..#127 : begin { First Character }
- FirstCharSel := Pos(UpCase(Ch1),FirstCharStr);
- if FirstCharSel <> 0 then
- begin
- Last := Current; Current := FirstCharSel;
- end
- else Write(#7); { Beep if error }
- end;
- #0 : begin
- Ch2 := ReadKey;
- case Ch2 of
- #80,#77 : begin { Down/Right Arrow }
- Last := Current;
- if Last <> ActualPicks then Current := Last + 1
- else Current := 1;
- end;
- #72,#75 : begin { Up/Left Arrow }
- Last := Current;
- if Last <> 1 then Current := Last - 1
- else Current := ActualPicks;
- end;
-
- #71,#73 : begin { Home/PgUp }
- Last := Current;
- Current := 1;
- end;
- #79,#81 : begin { End/PgDn }
- Last := Current;
- Current := ActualPicks;
- end;
- end;
- end;
- end;
- HiLite(False,Pick[Last]);
- HiLite(True,Pick[Current]);
- until (Ch1 = #13) or (FirstCharSel <> 0);
- CursorOn(True); { Unhide cursor }
- DisplayMenuGetPick:= Current;
- end; {DisplayMenuGetPick}
- {----------------------------------------------------------------------------}
- begin
- BkgdColor := Black;
- TxtColor := LightGray;
- end.